package com.flyou.ren.gateway.config;

import lombok.extern.log4j.Log4j2;
import org.springframework.cloud.gateway.filter.GatewayFilter;
import org.springframework.cloud.gateway.filter.factory.AbstractNameValueGatewayFilterFactory;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.stereotype.Component;

import java.net.InetSocketAddress;
@Log4j2
@Component
public class RequestLogGatewayFilterFactory extends AbstractNameValueGatewayFilterFactory {

	@Override
	public GatewayFilter apply(NameValueConfig config) {
		return (exchange, chain) -> {
			ServerHttpRequest request= exchange.getRequest();
			InetSocketAddress remoteAddress = request.getRemoteAddress();
			log.warn(request.getPath());
			log.warn(remoteAddress.toString());
			log.warn(request.getMethod());

			return chain.filter(exchange.mutate().request(request).build());
		};
	}

}